/**
 * 单词学习页面
 * @author 杨世峰
 */

<template>
  <div class="outer">
    <el-row>
      <el-col :span="8">
        <div>
          <h3></h3>
        </div>
      </el-col>
      <el-col :span="8">
        <div class="container">
          <div class="card">
            <div class="imgBx">
            </div>
            <div class="contentBx">
              <h1>{{ words[curIndex].wordSpell }}</h1>
              <div class="size">
                <h3>{{ words[curIndex].soundmark }}</h3>
                <h3>{{ words[curIndex].paraphrase }}</h3>
              </div>
              <div class="color">
                <h3>{{ words[curIndex].remark }}</h3>
              </div>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="8"></el-col>
    </el-row>
    <el-row style="margin-top: 50px">
      <el-col :span="8">
        <h3></h3>
      </el-col>
      <el-col :span="8">
        <div style="text-align: center;">
          <el-button type="primary" @click="handleUnRemember">不记得</el-button>
          <el-button type="primary" @click="handleRemember">记得</el-button>
        </div>
      </el-col>
      <el-col :span="8"></el-col>
    </el-row>
  </div>

</template>

<script>
import { getLearningWords, learnWords } from "@/api/user/bookletApi.js";
import dateUtils from "@/utils/date.js";

export default {
  data() {
    return {
      curIndex: 0,
      words: [
        {
          wordSpell: "TBD",
          soundmark: "TBD",
          paraphrase: "TBD",
          remark: "TBD",
        },
      ],
    };
  },
  computed: {

    roleId() {
      return this.$store.getters.roleId
    }
  },
  methods: {
    handleRemember() {
      // 学习次数加一
      this.words[this.curIndex].studyCount++;
      if (this.curIndex == this.words.length - 1) {
        this.handleLastWord();
      } else {
        this.curIndex++;
      }
    },

    handleUnRemember() {
      // 学习次数不加一
      if (this.curIndex == this.words.length - 1) {
        this.handleLastWord();
      } else {
        this.curIndex++;
      }
    },

    handleLastWord() {
      // 组装参数
      let data = [];
      let words = this.words;
      for (let i = 0; i < words.length; i++) {
        let entry = {
          entryId: words[i].entryId,
          studyCount: words[i].studyCount,
          lastStudyDatetime: dateUtils.date2YYYYMMdd(new Date()),
          remark: words[i].remark,
        };
        data.push(entry);
      }
      // 调用API TODO

      data = { list: data };
      console.log(data);
      learnWords(this.$route.params.bookletId, data)
        .then((res) => {
          console.log(res);
          this.$alert('<font color="red">' + res.message + " </font>", "提示", {
            dangerouslyUseHTMLString: true,
            type: res.resultCode == "200" ? "success" : "error",
          })
            .then(() => {
              if (this.roleId == 2) {
                this.$router.push({
                  name: "Booklets"
                 
                }).catch(() => { });
              } else if (this.roleId == 1) {
                this.$router.push({
                  name: "BookletsAdmin"
                  
                }).catch(() => { });
              }
            })
            .catch(() => { });
        })
        .catch();
    },
  },
  created() {
    // 调用 API，初始化当前页面数据
    getLearningWords(this.$route.params.bookletId)
      .then((res) => {
        if (res.data.length == 0) {
          this.$alert(
            '<font color="red">' +
            "当前单词本为空，添加几个单词后再来吧！" +
            " </font>",
            "提示",
            {
              dangerouslyUseHTMLString: true,
              type: res.resultCode == "200" ? "success" : "error",
            }
          )
            .then(() => {
              this.$router.push({ name: "Booklets" });
            })
            .catch(() => { });
        } else {
          this.words = res.data;
        }
      })
      .catch();
  },
};
</script>

<style scoped>
@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");

* {
  font-family: "Poppins", sans-serif;
}

.outer {
  margin-top: 10vh;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #131313;
}

.container {
  position: relative;
}

.container .card {
  position: relative;
  width: auto;
  height: 450px;
  background: #232323;
  border-radius: 20px;
  overflow: hidden;
}

.container .card:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #9bdc28;
  clip-path: circle(150px at 80% 20%);
  transition: 0.5s ease-in-out;
}

.container .card:hover:before {
  clip-path: circle(300px at 80% -20%);
}

.container .card:after {
  content: "M.E.";
  position: absolute;
  top: 30%;
  left: 15%;
  font-size: 12em;
  font-weight: 800;
  font-style: italic;
  color: rgba(255, 255, 25, 0.05);
}

.container .card .imgBx {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10000;
  width: 100%;
  height: 220px;
  transition: 0.5s;
}

.container .card:hover .imgBx {
  top: 0%;
  transform: translateY(0%);
}

.container .card .imgBx img {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-25deg);
  width: 270px;
}

.container .card .contentBx {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 100px;
  text-align: center;
  transition: 1s;
  z-index: 10;
}

.container .card:hover .contentBx {
  height: 210px;
}

.container .card .contentBx h1 {
  position: relative;
  font-weight: 600;
  letter-spacing: 1px;
  color: #fff;
  margin: 0;
}

.container .card .contentBx .size,
.container .card .contentBx .color {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px 20px;
  transition: 0.5s;
  opacity: 0;
  visibility: hidden;
  padding-top: 0;
  padding-bottom: 0;
}

.container .card:hover .contentBx .size {
  opacity: 1;
  visibility: visible;
  transition-delay: 0.5s;
}

.container .card:hover .contentBx .color {
  opacity: 1;
  visibility: visible;
  transition-delay: 0.6s;
}

.container .card .contentBx .size h3,
.container .card .contentBx .color h3 {
  color: #fff;
  font-weight: 300;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-right: 10px;
}

.container .card .contentBx .size span {
  width: 26px;
  height: 26px;
  text-align: center;
  line-height: 26px;
  font-size: 14px;
  display: inline-block;
  color: #111;
  background: #fff;
  margin: 0 5px;
  transition: 0.5s;
  color: #111;
  border-radius: 4px;
  cursor: pointer;
}

.container .card .contentBx .size span:hover {
  background: #9bdc28;
}

.container .card .contentBx .color span {
  width: 20px;
  height: 20px;
  background: #ff0;
  border-radius: 50%;
  margin: 0 5px;
  cursor: pointer;
}

.container .card .contentBx .color span:nth-child(2) {
  background: #9bdc28;
}

.container .card .contentBx .color span:nth-child(3) {
  background: #03a9f4;
}

.container .card .contentBx .color span:nth-child(4) {
  background: #e91e63;
}

.container .card .contentBx a {
  display: inline-block;
  padding: 10px 20px;
  background: #fff;
  border-radius: 4px;
  margin-top: 10px;
  text-decoration: none;
  font-weight: 600;
  color: #111;
  opacity: 0;
  transform: translateY(50px);
  transition: 0.5s;
  margin-top: 0;
}

.container .card:hover .contentBx a {
  opacity: 1;
  transform: translateY(0px);
  transition-delay: 0.75s;
}
</style>